package top.vanchor.myblog2back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import top.vanchor.myblog2back.entity.BlogReport;
import top.vanchor.myblog2back.mapper.BlogReportMapper;
import top.vanchor.myblog2back.service.IBlogReportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Ding
 * @since 2022-02-18
 */
@Service
public class BlogReportServiceImpl extends ServiceImpl<BlogReportMapper, BlogReport> implements IBlogReportService {

    @Resource
    private BlogReportMapper mapper;

    @Override
    public int toReport(BlogReport bean) {
        return mapper.insert(bean);
    }

    @Override
    public int isUserReported(BlogReport bean) {
        QueryWrapper<BlogReport> wrapper = new QueryWrapper<>();
        wrapper.eq("report_type",bean.getReportType());
        wrapper.eq("handle_user_id",bean.getHandleUserId());
        wrapper.eq("target_id",bean.getTargetId());
        wrapper.eq("report_status",0);
        return mapper.selectCount(wrapper);
    }

    @Override
    public PageInfo<BlogReport> getList(Integer pageNo, Integer pageSize, Integer type, Integer status) {
        PageHelper.startPage(pageNo,pageSize);
        return new PageInfo<>(mapper.getList(type,status));
    }

    @Override
    public int toDeal(BlogReport report,Integer resultCode) {
        QueryWrapper<BlogReport> wrapper = new QueryWrapper<>();
        wrapper.eq("report_id",report.getReportId());
        report.setReportStatus(resultCode);
        return mapper.update(report,wrapper);
    }

    @Override
    public BlogReport getReportById(Integer reportId) {
        return mapper.getReportById(reportId);
    }
}
